package cn.kpi.service.lawassessment.impl;

import cn.kpi.dao.lawassessment.LawKPIDao;
import cn.kpi.entity.lawassessment.KpiWeight;
import cn.kpi.entity.lawassessment.LawKPItemEntity;
import cn.kpi.service.lawassessment.ILawKPIService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;
import java.util.Map;

/**
 * 队伍考核打分
 *
 * @author lex
 * @create 2018-06-20-11:22
 */
@Controller
public class LawKPIServiceImpl implements ILawKPIService {


    @Autowired
    private LawKPIDao lawKPIDao;


    @Override
    public List<Map> GetLawKPIMapByTempIdAndColumns(Long tempid, String columns,String groupByColums) throws Exception {
        try {

            return lawKPIDao.GetBUKPIMapByTempIdAndColumns(tempid, columns,groupByColums);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    @Override
    public List<Map> getRedScore(Long templateid) {
        return  lawKPIDao.getRedScore(templateid);
    }

    @Override
    public int InsertLawKPItemBatch(Long templateid, List<LawKPItemEntity> list) throws Exception {
        try {
            int result = lawKPIDao.DeleteBUKPItem(templateid);
            result += lawKPIDao.InsertBUKPItemBatch(list);
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//回滚事物
            return -1;
        }
    }

    @Override
    public int InsertKpiWeight(List<KpiWeight> list) {

        try {
            if (list != null && list.size() > 0) {

                lawKPIDao.DeleteKPIWeight(list.get(0).getTemplateid());
                lawKPIDao.InsertKPIWeight(list);
                return 1;
            }


        } catch (Exception ex) {
            return 0;

        }
        return 0;
    }

    @Override
    public List<KpiWeight> GetKpiWeights(int templateid) {
        return lawKPIDao.GetKPIWeights(templateid);
    }

    @Override
    public List<Map> GetWeight(int templateid) {
        try {
            return lawKPIDao.GetWeight(templateid);
        } catch (Exception ex) {
            return null;
        }
    }
}
